package com.itc.common.core.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeUtils {

    /**
     * 获取当前时间
     * @return
     */
    public static String getCurrentLocalDateTime(){
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = now.format(formatter);
        return formattedDateTime;
    }

    /**
     * 获取当前时间
     * @return
     */
    public static String getCurrentLocalDateTime(String pattern){
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        String formattedDateTime = now.format(formatter);
        return formattedDateTime;
    }

    /**
     * LocalDateTime时间格式转换
     * @param time
     * @param pattern
     * @return
     */
    public static LocalDateTime stringToLocalDateTime(String time, String pattern) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        return LocalDateTime.parse(time,formatter);
    }
}
